package com.springboot.controller;

import com.springboot.model.NavigationRecord;
import com.springboot.model.NavigationRecordKey;
import com.springboot.model.UserLoginForm;
import com.springboot.service.TableBarService;
import com.springboot.service.UserLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class PatientTablebarController {
    @Autowired
    TableBarService tableBarService;

    @Autowired
    UserLoginService userLoginService;
    /*
     * @ description:患者端设置tablebar
     * @ param      :[tel, tableBarId]
     * @ return     :void
     * @ date       :2021/1/1

    */
    @CrossOrigin
    @RequestMapping(value = "/patientsettablebar")
    @ResponseBody
    public void patientSetTableBar(@RequestParam("unitphone") String tel,
                                   @RequestParam("pageNum") Integer tableBarId) {
        UserLoginForm userLoginForm = userLoginService.findUserByTel(tel);
        Integer userId = userLoginForm.getUserId();
        NavigationRecordKey navigationRecordKey = new NavigationRecordKey(userId,tableBarId);
        try {
            tableBarService.addTableBar(navigationRecordKey);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    @CrossOrigin
    @RequestMapping(value = "/getMostEnterPage")
    @ResponseBody
    public Integer patientSetTableBar(@RequestParam("doctorTel") String tel) {
        UserLoginForm userLoginForm = userLoginService.findUserByTel(tel);
        Integer userId = userLoginForm.getUserId();
        NavigationRecord navigationRecord = new NavigationRecord();
        try {
            navigationRecord = tableBarService.showTableBarNum(userId);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return navigationRecord.getTablebarId();
    }
}
